var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/businessComponent/work-flow/WFCommonPhrases.tsx
var WFCommonPhrases_exports = {};
__export(WFCommonPhrases_exports, {
  WFCommonPhrases: () => WFCommonPhrases
});
module.exports = __toCommonJS(WFCommonPhrases_exports);
var import_react = require("react");
var import_functionalComponent = require("../../functionalComponent");
var import_util = require("../../util");
var import_service = require("./service");
var import_util2 = require("./util");
function WFCommonPhrases({ callback }) {
  const mCtx = (0, import_react.useContext)(import_functionalComponent.ModalContext);
  const [tableloading, settableloading] = (0, import_react.useState)(true);
  const [addButtonLoading, setaddButtonLoading] = (0, import_react.useState)(false);
  const [deleteButtonLoading, setdeleteButtonLoading] = (0, import_react.useState)(false);
  const [deletetList, setDeletetList] = (0, import_react.useState)(new Array());
  const [ds, setDs] = (0, import_react.useState)([]);
  (0, import_react.useEffect)(() => {
    mCtx.ins.setApi({
      invokeOkHandler: async () => {
        var _a, _b;
        console.log(import_util.iup.getCmpApi("editCommonPhrasesTable").validData(), "sds");
        if (!((_a = import_util.iup.getCmpApi("editCommonPhrasesTable")) == null ? void 0 : _a.validData())) {
          (0, import_util2.wfAlert)("错误提示", "常用语不能为空");
          return;
        }
        callback();
        (_b = mCtx.ins) == null ? void 0 : _b.destroy();
      }
    });
  }, []);
  (0, import_react.useEffect)(() => {
    (0, import_service.getCommonWordHelp)().then((res) => {
      setDs(res);
      settableloading(false);
    });
  }, []);
  const columns = [
    {
      dataIndex: "id",
      hidden: true
    },
    {
      title: "常用语句",
      width: 80,
      // flex 存在时，width 为最小宽度
      flex: 1,
      dataIndex: "content",
      editor: {
        xtype: "input",
        required: true,
        listeners: {
          onChange(e) {
            var _a;
            console.log(e);
            (0, import_service.createOrUpdateContent)(e.value, (_a = e == null ? void 0 : e.row) == null ? void 0 : _a.id);
          }
        }
      }
    }
  ];
  return /* @__PURE__ */ React.createElement("div", { style: { padding: "10px 20px 0 20px", height: 340 } }, /* @__PURE__ */ React.createElement(import_util.Layout, null, /* @__PURE__ */ React.createElement(import_util.Layout, { style: { marginBottom: "10px" }, direction: "row" }, /* @__PURE__ */ React.createElement(
    import_functionalComponent.Button,
    {
      style: { width: "80px", marginRight: "10px" },
      type: "primary",
      loading: addButtonLoading,
      onClick: () => {
        setaddButtonLoading(true);
        (0, import_service.createOrUpdateContent)(import_util2.NGLang.commonPhrases).then((res) => {
          if (res.code === 0) {
            import_util.iup.getCmpApi("editCommonPhrasesTable").addRows({ id: res.data, content: import_util2.NGLang.commonPhrases });
          }
          if (res) {
            setaddButtonLoading(false);
          }
        });
      }
    },
    "新增"
  ), /* @__PURE__ */ React.createElement(
    import_functionalComponent.Button,
    {
      style: { width: "80px" },
      loading: deleteButtonLoading,
      disabled: deletetList.length == 0,
      onClick: async () => {
        setdeleteButtonLoading(true);
        settableloading(true);
        (0, import_service.deleteContentById)(deletetList.map((i) => i.id)).then((res) => {
          if (res) {
            (0, import_service.getCommonWordHelp)().then((res2) => {
              setDs(res2);
              setDeletetList([]);
              settableloading(false);
            });
          }
        });
      }
    },
    "删除"
  )), /* @__PURE__ */ React.createElement(import_util.Layout.Flex, null, /* @__PURE__ */ React.createElement(
    import_functionalComponent.Table,
    {
      bordered: true,
      checkbox: true,
      loading: tableloading,
      onCheckedChange: (a, b) => {
        setDeletetList(a);
      },
      editColumnIcon: true,
      style: { height: 250 },
      id: "editCommonPhrasesTable",
      columns,
      dataSource: ds
    }
  ))));
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  WFCommonPhrases
});
